package com.songtai.action.front;

import java.util.List;

import com.songtai.action.SongtaiActionSupport;
import com.songtai.po.News;
import com.songtai.po.Node;
import com.songtai.po.PhotoObj;
import com.songtai.po.PublicObj;
import com.songtai.pojo.NodeView;
import com.songtai.service.ImageService;
import com.songtai.service.NewsService;
import com.songtai.service.NodeService;
import com.songtai.service.PublicObjService;
import com.songtai.util.CommenUtil;
import com.songtai.util.Pager;

/**
 * @author 赵中杨
 * @email zhaozhongyang717@gmail.com
 * @date 2010 2010-4-21 下午05:38:01
 */
public class NewsAction extends SongtaiActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6854341201349783508L;
	private NodeService nodeService;
	private NewsService newsService;
	private List<NodeView> nodeView;
	private Pager<News> newsItem;
	private News news;
	private Node currentNode;
	private Long nodeid;
	private Long newsid;
	private int parent;
	private int currentPage;
	private String keyword;
	private Long parentId = 9L;
	private Long slider_id = 2L;
	private List<PhotoObj> sliderList;
	private ImageService imageService;
	private int hasSummary = 0;
	private int type = 0;

	private List<PublicObj> qq;
	private PublicObjService publicObjService;

	/**
	 * @return the sliderList
	 */
	public List<PhotoObj> getSliderList() {
		return sliderList;
	}

	/**
	 * @param sliderList
	 *            the sliderList to set
	 */
	public void setSliderList(List<PhotoObj> sliderList) {
		this.sliderList = sliderList;
	}

	/**
	 * @return the imageService
	 */
	public ImageService getImageService() {
		return imageService;
	}

	/**
	 * @param imageService
	 *            the imageService to set
	 */
	public void setImageService(ImageService imageService) {
		this.imageService = imageService;
	}

	/**
	 * 新闻详细信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String newsDetail() throws Exception {
		if (newsid < 1) {
			return null;
		}
		// 兄弟节点
		nodeView = nodeService.getChildren(parentId);
		// 当前新闻
		news = newsService.getNewsById(newsid);
		if (news != null && !CommenUtil.isEmpty(news.getSummary())) {
			hasSummary = 1;
		}
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10,
				PhotoObj.TYPE_SLIDER);
		qq = publicObjService.getObjsByNid("23");
		return SUCCESS;
	}

	/**
	 * 新闻列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String newsList() throws Exception {
		if (currentPage < 1) {
			currentPage = 1;
		}
		// 如果是父节点，则获取子节点，反之，则获取兄弟节点
		int pageSize = 10;
		if (nodeid == null || nodeid == 0) {
			nodeView = nodeService.getChildren(parentId);
			newsItem = newsService.getNews(currentPage, pageSize);
			newsItem.setPageSize(pageSize);
		} else {
			nodeView = nodeService.getAllBrothers(nodeid);
			newsItem = newsService.getNewsListByNodeid(nodeid, currentPage,
					pageSize);
			newsItem.setPageSize(pageSize);
			// 当前节点
			currentNode = nodeService.getNodeById(nodeid);
		}
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10,
				PhotoObj.TYPE_SLIDER);
		qq = publicObjService.getObjsByNid("23");
		return SUCCESS;
	}

	/**
	 * 搜索新闻
	 * 
	 * @return
	 * @throws Exception
	 */
	public String searchNews() throws Exception {
		if (currentPage < 1) {
			currentPage = 1;
		}
		type = 1;
		if (!CommenUtil.isEmpty(keyword)) {
			// 如果是父节点，则获取子节点，反之，则获取兄弟节点
			if (nodeid == null || nodeid == 0) {
				nodeView = nodeService.getChildren(parentId);
			} else {
				nodeView = nodeService.getAllBrothers(nodeid);
			}
			int pageSize = 1;
			newsItem = newsService.searchNews(currentPage, pageSize, keyword);
			newsItem.setPageSize(pageSize);
		}
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10,
				PhotoObj.TYPE_SLIDER);
		qq = publicObjService.getObjsByNid("23");
		return SUCCESS;
	}

	/**
	 * @return the nodeid
	 */
	public Long getNodeid() {
		return nodeid;
	}

	/**
	 * @param nodeid
	 *            the nodeid to set
	 */
	public void setNodeid(Long nodeid) {
		this.nodeid = nodeid;
	}

	/**
	 * @return the newsid
	 */
	public Long getNewsid() {
		return newsid;
	}

	/**
	 * @param newsid
	 *            the newsid to set
	 */
	public void setNewsid(Long newsid) {
		this.newsid = newsid;
	}

	/**
	 * @return the nodeService
	 */
	public NodeService getNodeService() {
		return nodeService;
	}

	/**
	 * @param nodeService
	 *            the nodeService to set
	 */
	public void setNodeService(NodeService nodeService) {
		this.nodeService = nodeService;
	}

	/**
	 * @return the newsService
	 */
	public NewsService getNewsService() {
		return newsService;
	}

	/**
	 * @param newsService
	 *            the newsService to set
	 */
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}

	/**
	 * @return the nodeView
	 */
	public List<NodeView> getNodeView() {
		return nodeView;
	}

	/**
	 * @param nodeView
	 *            the nodeView to set
	 */
	public void setNodeView(List<NodeView> nodeView) {
		this.nodeView = nodeView;
	}

	/**
	 * @return the news
	 */
	public News getNews() {
		return news;
	}

	/**
	 * @param news
	 *            the news to set
	 */
	public void setNews(News news) {
		this.news = news;
	}

	/**
	 * @return the currentNode
	 */
	public Node getCurrentNode() {
		return currentNode;
	}

	/**
	 * @param currentNode
	 *            the currentNode to set
	 */
	public void setCurrentNode(Node currentNode) {
		this.currentNode = currentNode;
	}

	/**
	 * @return the parent
	 */
	public int getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(int parent) {
		this.parent = parent;
	}

	/**
	 * @return the newsItem
	 */
	public Pager<News> getNewsItem() {
		return newsItem;
	}

	/**
	 * @param newsItem
	 *            the newsItem to set
	 */
	public void setNewsItem(Pager<News> newsItem) {
		this.newsItem = newsItem;
	}

	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * @return the keyword
	 */
	public String getKeyword() {
		return keyword;
	}

	/**
	 * @param keyword
	 *            the keyword to set
	 */
	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	/**
	 * @return the hasSummary
	 */
	public int getHasSummary() {
		return hasSummary;
	}

	/**
	 * @param hasSummary
	 *            the hasSummary to set
	 */
	public void setHasSummary(int hasSummary) {
		this.hasSummary = hasSummary;
	}

	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}

	public List<PublicObj> getQq() {
		return qq;
	}

	public void setQq(List<PublicObj> qq) {
		this.qq = qq;
	}

	/**
	 * @return the publicObjService
	 */
	public PublicObjService getPublicObjService() {
		return publicObjService;
	}

	/**
	 * @param publicObjService
	 *            the publicObjService to set
	 */
	public void setPublicObjService(PublicObjService publicObjService) {
		this.publicObjService = publicObjService;
	}

}
